﻿using System.Windows;
using System.Windows.Controls;
using Bookvar.ObjectModel;
using Bookvar.UI.ViewModel;

namespace BookvarWpf.Windows
{
    /// <summary>
    /// Interaction logic for AddHyperlink.xaml
    /// </summary>
    public partial class AddHyperlinkWindow
    {
        private readonly HyperlinkWindowViewModel viewModel;

        public AddHyperlinkWindow( Topic topic )
        {
            InitializeComponent();

            viewModel = new HyperlinkWindowViewModel( topic );
            ViewModelBase.AddCommandAndInputBindings( this, viewModel );

            txtHyperlink.SetBinding( TextBox.TextProperty, viewModel.CreateTopicHyperlinkBinding() );

            Loaded += delegate
                      {
                          txtHyperlink.Focus();
                          txtHyperlink.SelectAll();
                      };
        }

        private void OnOkClick( object sender, RoutedEventArgs e )
        {
            CloseCommand.Execute( null, this );
        }
    }
}